Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a few cases commands to fun.py to output a string in a specific case. #1455

Closed
wants to merge 11 commits into from

Conversation

JelmerKorten
Copy link
Member

Relevant Issues

Closes #707 if approved.

Description

  • Added 4 commands to fun.py to output a string in different cases to add to the already existing .randomcase
    pascalCase, CamelCase, snake_case, SCREAMING_SNAKE_CASE
    .pascalcase aliases [.pascal .pcase]
    .camelcase aliases [.camel .ccase]
    .snakecase alias [.scase]
    .screamingsnakecase aliases [.screamsnake .ssnake .screamingsnake]
  • Added a helper function in utils/helpers.py to attempt to strip a string of punctuation and case.

Did you:

Copy link
Member

@shtlrs shtlrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a code review, didn't test this yet.

bot/exts/fun/fun.py Show resolved Hide resolved
@Xithrius Xithrius added area: backend Related to internal functionality and utilities status: needs review Author is waiting for someone to review and approve type: enhancement Changes or improvements to existing features category: fun Related to fun and games labels Feb 12, 2024
bot/utils/helpers.py Show resolved Hide resolved
@@ -51,6 +51,21 @@ def _get_random_die() -> str:
die_name = f"dice_{random.randint(1, 6)}"
return getattr(Emojis, die_name)

@staticmethod
async def _clean_fun_cog_text(ctx: Context, text: str, conversion_func: Callable[[str], str]) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should not do the sending part, let it just clean the text & embed and return them as a tuple.

Also, the fun_cog in the function name is a redundant since it's a private function of the Fun cog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey!
Thanks for the feedback. I've changed the name and the function now returns said tuple.
I'm struggling to put the BadArgument check in self._clean_text for some reason. I've now got the raise BadArgument added though and it's working. But I don't like the repeating of it.

Copy link
Member

@shtlrs shtlrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I haven't seen these before.
One final sweep, and should be good.


@commands.command(name="pascalcase", aliases=("pcase", "pascal",))
async def pascalcase_command(self, ctx: Context, *, text: str | None) -> None:
"""Attempts to convert the provided string to pascalCase."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i'm not mistaken, it's the other way around where PascalCase should be pascalCase and CamelCase should be camelCase

So both docstrings & conversion functions need to be switched

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cant believe I had them the wrong way around hey. Fixed in both files now xD

return "_".join(
text.split()
)
converted_text, embed = await self._clean_text(ctx, text, conversion_func)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit

Suggested change
converted_text, embed = await self._clean_text(ctx, text, conversion_func)
cleaned_text, embed = await self._clean_text(ctx, text, conversion_func)

Since the function's name indicates "cleaning" rather than "converting"

"""Attempts to convert the provided string to pascalCase."""
text = helpers.neutralise_string(text)
def conversion_func(text: str) -> str:
"""Converts the provided string to pascalCase."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same note here for the docstring about the pascal & camel case notation

def conversion_func(text: str) -> str:
"""Converts the provided string to CamelCase."""
return "".join(
word[0].upper()+word[1:] for word in text.split()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a native way of doing this

Suggested change
word[0].upper()+word[1:] for word in text.split()
word.capitalize() for word in text.split()

def conversion_func(text: str) -> str:
"""Converts the provided string to pascalCase."""
return "".join(
word[0].upper()+word[1:] if i != 0 else word for i, word in enumerate(text.split())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing about the usage of capitalize here

@JelmerKorten
Copy link
Member Author

Closing this because of the source branch change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: backend Related to internal functionality and utilities category: fun Related to fun and games status: needs review Author is waiting for someone to review and approve type: enhancement Changes or improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New .case commands
3 participants